{layout name="public/layout" /}
{include file='yxnavbar'}


<div class="main">
    {include file='koi_common_nav'}
    <div class="panel panel-info">
        <div class="panel-heading">当前数量： {$page_total}</div>
        <div class="panel-body">
            <form id = "myform" action="./index.php" method="get" class="form-horizontal" role="form">
                <input type="hidden" name="c" value="site" />
                <input type="hidden" name="a" value="entry" />
                <input type="hidden" name="m" value="{$_P['m']}" />
                <input type="hidden" name="op" value="{$ac}" />
                <input type="hidden" name="do" value="{$do}" />

                <div class="form-group">
                    {if count($themelist)>1}
                    <div class="col-xs-12 col-sm-2 col-md-2">
                        <select onchange="submitForm();" class="form-control" name="themeid">
                            {loop $themelist $row}
                            <option value="{$row['id']}" {if $themeid == $row['id'] }selected="selected"{/if}>{$row['id']} - {php echo mb_substr($row['title'],0,8,'utf-8');}</option>
                            {/loop}
                        </select>
                    </div>
                    {else}
                    <input type="hidden" name="themeid" value="{$themeid}" />
                    {/if}
                </div>
<!--                </div>-->
                <div class="form-group">
                    <div class="col-sm-3 col-lg-3 col-md-3 col-xs-6">
                        <a href="{php echo createWebUrl('koi',array('themeid'=>$themeid,'op'=>'prize_add'));}" class="btn {if $op == 'prize_add'}btn-primary{else}btn-default{/if}">添加奖项</a>
                    </div>
                    <div class="col-sm-5 col-xs-12">
                        <div class="input-group">
                            <span class="input-group-addon">将中奖概率为：</span>
                            <input type="text" class="form-control"  placeholder="" id="old_pr" name="old_pr"  value="">
                            <span class="input-group-addon">修改为</span>
                            <input type="text" class="form-control"  placeholder="" id="new_pr" name="new_pr"  value="">
                            <span class="input-group-addon">中奖概率</span>
                        </div>
                    </div>
                    <div class="col-sm-3 col-lg-3 col-md-3 col-xs-6">
                        <a class="btn btn-default" onclick="allEdit()"><i class="fa fa-search"></i> 批量修改</a>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-5 col-lg-5 col-md-5 col-xs-5">
                        <input class="btn btn-default" type="submit" name="export_submit" onclick="jump()" id="export_submit" value="导出EXCEL">
                    </div>
                </div>
            </form>
            <form id = "uploadForm"  class="form-horizontal" role="form">
                <input type="hidden" name="c" value="site" />
                <input type="hidden" name="a" value="entry" />
                <input type="hidden" name="m" value="{$_P['m']}" />
                <input type="hidden" name="do" value="{$do}" />
                <input type="hidden" name="themeid" value="{$themeid}" />

                <div class="form-group">
                    <div class="col-sm-5 col-xs-12">
                        <div class="input-group">
                            <input type="file" class="form-control" name="file"  value="">
                        </div>
                    </div>
                    <div class="col-sm-3 col-lg-3 col-md-3 col-xs-6">
                        <a class="btn btn-default" onclick="uploadFile()"><i class="fa fa-search"></i> 上传文件</a>
                        <a class="btn btn-default" href="https://css2020.yixuan.net/2019css/koi/five_koi_demo.xlsx"><i class="fa fa-search"></i> 模版下载</a>
                    </div>
                </div>

            </form>
        </div>
    </div>

    <input type="hidden" name="current_ac" id="current_ac" value="{$ac}">
    <input type="hidden" name="themeid" id="themeid" value="{$themeid}">
    <!--  列表框  -->
    <div class="tab-content">
        <div class="panel panel-default">
            <div class="panel-body table-responsive">
                <table class="table table-hover">
                    <thead class="navbar-inner">
                    <tr>
                        <th style="width: 50px">序号</th>
                        <th style="width: 120px">奖品简称</th>
                        <th style="width: 120px">奖品描述</th>
                        <th style="width: 100px">奖品库存</th>
                        <th style="width: 100px">奖品价值</th>
                        <th style="width: 100px">归属锦鲤</th>
                        <th style="width: 100px">中奖概率</th>
                        <th style="width: 100px">展示排序</th>
                        <th style="width: 100px">奖品小图</th>
                        <th style="width: 80px">状态</th>
                        <th style="width: 80px">奖品类型</th>
                        <th style="width: 120px">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {loop $list $item}
                    <tr>
                        <td>{$item['p_id']}</td>
                        <td>{$item['name']}</td>
                        <td>{$item['short_name']}</td>
                        <td>{$item['qty']}</td>
                        <td>{$item['price']}元</td>
                        <td>{php echo formatLotteryKoi($item['koi_id'],$lottery_koi);}</td>
                        <td>{php echo $item['pr']/100;}</td>
                        <td>{$item['show_sort']}</td>
                        <td>
                            <a href="{php echo tomedia($item['small_img']);}"  target="_blank" title="查看原图">
                                <img src="{php echo tomedia($item['small_img']);}" style="width: 60px;height: 60px;padding: 1px;">
                            </a>
                        </td>
                        <td>
                            {if $item['status']==2}
                            <span class="label label-warning">未启用</span>
                            {else}
                            <span class="label label-success">启用</span>
                            {/if}
                        </td>
                        <td>
                            {if $item['is_lose']==1}
                            <span class="label label-warning">必中奖项</span>
                            {else}
                            <span class="label label-success">正常奖项</span>
                            {/if}
                        </td>
                        <td>
                            <a class="btn btn-primary btn-sm" style="width: 35px" href="{php echo createWebUrl('koi', array('op' =>'prize_edit','themeid'=>$themeid,'p_id'=>$item['p_id']));}" ><i class="fa fa-pencil-square-o"> </i></a>
                            <a class="btn btn-primary btn-sm" style="width: 35px" onclick="changeOrDelLttInfo(this)" data-type="del" data-edit-url="{php echo createWebUrl('koi', array('op' =>'prize_edit','themeid'=>$themeid,'p_id'=>$item['p_id']));}" data-themeid="{$themeid}" data-id="{$item['p_id']}"  title="删除" data-toggle="tooltip" data-placement="top"><i class="fa fa-times"> </i></a>
                        </td>
                    </tr>
                    {/loop}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
{$pager}
<script type="text/javascript">
    $(document).ready(
        function (){
            var page_total = "<?php echo $page_total;?>";
            if (page_total%3==0){

            }else{
                layer.msg('请添加奖品，直到奖品的数量为3的倍数');
            }
        }
    );
    function jump(){
        layer.msg('正在准备下载');
    }
    function submitForm(){
        var form = document.getElementById("myform");
        form.submit();
    }
    function allEdit(){
        var old_pr = $("#old_pr").val();
        var new_pr = $("#new_pr").val();
        var themeid = $("#themeid").val();
        if (!old_pr || !new_pr){
            layer.msg('请检查批量修改条件');
            return;
        }else{
                postUrl = "{php echo createWebUrl('koi',array('op' =>'prize_all_update'));}";
                layer.msg('您确定批量修改对应条件的记录吗？',{
                    btn:['确定','取消'],
                    yes:function (index) {
                        $.ajax({
                            url:postUrl,
                            dataType:'json',
                            method:'post',
                            data: {old_pr:old_pr,new_pr:new_pr,themeid:themeid},
                            success:function (e) {
                                let res = e.message;
                                let code = res.code;
                                let msg = res.msg;
                                if (code!=200){
                                    layer.msg(msg);
                                }else{
                                    layer.msg(msg);
                                    location.reload();
                                }
                            },
                            fail:function (err) {
                                console.log(err)
                            }
                        });
                    }
                });
        }
    }
    function uploadFile(){
        var formData = new FormData($( "#uploadForm" )[0]);
        postUrl = "{php echo createWebUrl('koi',array('op' =>'prize_excel_insert'));}";
        layer.msg('您确定删除现有记录，并导入电子表格中的全部记录吗？',{
            btn:['确定','取消'],
            yes:function (index) {
                $.ajax({
                    url:postUrl,
                    dataType:'json',
                    method:'post',
                    data: formData,
                    processData: false,
                    contentType: false,
                    success:function (e) {
                        let res = e.message;
                        let code = res.code;
                        let msg = res.msg;
                        if (code!=200){
                            layer.msg(msg);
                        }else{
                            layer.msg(msg);
                            location.reload();
                        }
                    },
                    fail:function (err) {
                        console.log(err)
                    }
                });
            }
        });

    }
    function drop_confirm(msg, url){
        if(confirm(msg)){
            window.location = url;
        }
    }
    // 修改、删除
    function changeOrDelLttInfo(e) {
        let p_id = e.getAttribute("data-id");
        let type = e.getAttribute("data-type");
        let themeid = e.getAttribute("data-themeid");
        let redirectUrl = e.getAttribute("data-edit-url");
        let postUrl ="";
        if (type=='edit'){
            window.location.href = redirectUrl;
        }
        if (type=='del'){
            postUrl = "{php echo createWebUrl('koi',array('op' =>'prize_del'));}";
            layer.msg('您确定删除该记录吗？',{
                btn:['确定','取消'],
                yes:function (index) {
                    $.ajax({
                        url:postUrl,
                        dataType:'json',
                        method:'post',
                        data: {p_id:p_id,themeid:themeid},
                        success:function (e) {
                            let res = e.message;
                            let code = res.code;
                            let msg = res.msg;
                            if (code!=200){
                                layer.msg(msg);
                            }else{
                                layer.msg(msg);
                                location.reload();
                            }
                        },
                        fail:function (err) {
                            console.log(err)
                        }
                    });
                }
            });
        }
    }
</script>
